package yns.http;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Map;

public class HttpRequest {
	
	private String requestMethod;
	
	private String sendURL;
	private Map<String, String> requestProperty;
	private String param;
	
	private boolean doOutput;
	private boolean doInput;
	private boolean useCaches;
	private int connectTimeout;
	private int readTimeout;
	private boolean instanceFollowRedirects;
	
	private Proxy proxy;
	private String proxyHost;
	private int proxyPort;
	
	private void init() {
		this.requestMethod = HttpProperty.GET;
		
		this.doOutput = true;
		this.doInput = true;
		this.useCaches = false;
		this.connectTimeout = 60 * 1000;
		this.readTimeout = 2 * 60 * 1000;
		this.instanceFollowRedirects = true;
		
		this.proxy = Proxy.NO_PROXY;
	}
	
	public HttpRequest(){
		init();
	}

	public HttpRequest(String sendURL) {
		super();
		this.sendURL = sendURL;
		init();
	}

	public HttpRequest(String requestMethod, String sendURL) {
		super();
		this.requestMethod = requestMethod;
		this.sendURL = sendURL;
		init();
	}
	
	public void useProxy(String host,int port) throws IOException{
		this.proxyHost = host;
		this.proxyPort = port;
		
		InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port);
		this.proxy = new Proxy(Proxy.Type.HTTP,inetSocketAddress);
	}

	public String getRequestMethod() {
		return requestMethod;
	}

	public void setRequestMethod(String requestMethod) {
		this.requestMethod = requestMethod;
	}

	public String getSendURL() {
		return sendURL;
	}

	public void setSendURL(String sendURL) {
		this.sendURL = sendURL;
	}

	public Map<String, String> getRequestProperty() {
		return requestProperty;
	}

	public void setRequestProperty(Map<String, String> requestProperty) {
		this.requestProperty = requestProperty;
	}

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}

	public boolean isDoOutput() {
		return doOutput;
	}

	public void setDoOutput(boolean doOutput) {
		this.doOutput = doOutput;
	}

	public boolean isDoInput() {
		return doInput;
	}

	public void setDoInput(boolean doInput) {
		this.doInput = doInput;
	}

	public boolean isUseCaches() {
		return useCaches;
	}

	public void setUseCaches(boolean useCaches) {
		this.useCaches = useCaches;
	}

	public int getConnectTimeout() {
		return connectTimeout;
	}

	public void setConnectTimeout(int connectTimeout) {
		this.connectTimeout = connectTimeout;
	}

	public int getReadTimeout() {
		return readTimeout;
	}

	public void setReadTimeout(int readTimeout) {
		this.readTimeout = readTimeout;
	}

	public boolean isInstanceFollowRedirects() {
		return instanceFollowRedirects;
	}

	public void setInstanceFollowRedirects(boolean instanceFollowRedirects) {
		this.instanceFollowRedirects = instanceFollowRedirects;
	}

	public Proxy getProxy() {
		return proxy;
	}

	public String getProxyHost() {
		return proxyHost;
	}

	public int getProxyPort() {
		return proxyPort;
	}

}
